package com.itheima.controller;

import com.itheima.domain.Record;
import com.itheima.domain.User;
import com.itheima.entity.PageResult;
import com.itheima.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class RecordController {

    @Autowired
    private RecordService recondService;

    @RequestMapping("/recond")
    private ModelAndView searchreconds(Record recond, int pageNum, int pageSize, HttpServletRequest request){
        if(pageNum==0){
            pageNum=1;
        }
        if(pageSize==0){
            pageSize=10;
        }
       User userSession = (User)request.getSession().getAttribute("USER_SESSION");
        PageResult pageresult = recondService.searchrecond(recond, userSession, pageNum, pageSize);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("recond");
        modelAndView.addObject("pageresult", pageresult);
        modelAndView.addObject("search",recond);
        modelAndView.addObject("pageNum",pageNum);
        modelAndView.addObject("gourl",request.getRequestURI());
        return modelAndView;
    }
}
